#include "main.h"
float spin=0.0;

GLUquadric *sun,*space;
GLuint sunTexture,spaceTexture;


void drawSun()
{
//initilizing sun(light source) position 
GLfloat position[] = { 0.0, 0.0, 1.5, 1.0 };
// Set the light source parameters
glLightfv(GL_LIGHT0, GL_POSITION, position);
// Disable lighting conditions
glDisable(GL_LIGHTING);
//Enable textures
glEnable ( GL_TEXTURE_2D );
//Aplyin texture
glBindTexture ( GL_TEXTURE_2D, sunTexture);
glMatrixMode(GL_MODELVIEW);
//Push matrix
glPushMatrix();
// Multiply the current matrix by a translation matrix
glTranslated (0.0, 0.0, 0.0);
//Rotate the sphere by 90 degrees on the x axis
glRotated(90,1.0,0.0,0.0);
//Spin sphere
glRotated((GLdouble) spin, 0.0, 0.0, 1.0);
glColor4f(1.0,1.0,0,0.5);
// Draw a sphere
gluSphere(sun, sunRad-0.02, 100, 100);
//Enable blend mode, This will make textures transparents
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//set color and transparency below texture
glColor4f(1.0,0.8,0.0,0.6);
//Spin sun along self axis
glRotated((GLdouble) spin*2, 0.0, 0.5, -0.5);
//draw sphere
gluSphere(sun, sunRad, 100, 100);
//set color for space box
glColor4f(1.0,1.0,1.0,0.0);
//Disable blending mode
glDisable(GL_BLEND);
//Pop matrix
glPopMatrix();
//Push matrix
glPushMatrix();
//---------------------Create Space Box-----------------------
//Aplyin texture
glBindTexture ( GL_TEXTURE_2D, spaceTexture);
glMatrixMode(GL_MODELVIEW);
// Multiply the current matrix by a translation matrix
glTranslated (0.0, 0.0, 0.0);
//Rotate 90 degrees on x axis
glRotated(90,1.0,0.0,0.0);
//Draw a sphere
gluSphere(space, 55, 25, 25);
//Rotate -90 degrees on x axis
glRotated(-90,1.0,0.0,0.0);
//disable textures
glDisable(GL_TEXTURE_2D);
//Pop matrix
glPopMatrix();
char s[]={"Black hole"};
int len, i;
glRasterPos3f(0,45,0.0);
len=(int)strlen(s);
for (i=0;i<len;i++)   glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, s[i]);
glRasterPos3f(0,-45,0.0);
len=(int)strlen(s);
for (i=0;i<len;i++)   glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, s[i]);

//Enable lighting
glEnable(GL_LIGHTING);
}
//Initialize the sun texture
void initSun()
{
  glLoadIdentity();
  glOrtho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
     
  sun = gluNewQuadric();
  gluQuadricTexture( sun, GL_TRUE);
  sunTexture = LoadBitmap("textures/sun.bmp");
 
  glLoadIdentity();
  glOrtho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
     
  space = gluNewQuadric();
  gluQuadricTexture( space, GL_TRUE);
  spaceTexture = LoadBitmap("textures/spacetex1.bmp");
}
//Spin the sun
void spinSun()
{
	//Update rotation speed(angle)
	spin +=0.15;
	// Spin for ever
	if (spin > 360.0)
	spin = spin - 360.0;
}